home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Think Class Libraries / CMIDI 2.2 / CMIDIClient.cp < prev    next >
Encoding:
Text File  |  1994-11-30  |  4.6 KB  |  142 lines  |  [TEXT/KAHL]

  1. /*
  2.  *——— CMIDIClient.cp ————————————————————————————————————————————————————————————————————
  3.  * Copyright © Paul Ferguson, 1990-94.  All rights reserved.
  4.  *
  5.  * Superclass:  CObject
  6.  * Subclasses:  None
  7.  *
  8.  * Description:
  9.  *    CMIDIClient.c defines a MIDI Manager client object.
  10.  *
  11.  *    For use with Symantec C++ 6.0, the accompanying THINK Class Library (TCL), and MIDI
  12.  *    Manager 2.0. Refer to the accompanying Microsoft Word document for complete
  13.  *    details about MIDI Manager objects.
  14.  *
  15.  *    If you have comments or questions about this code, you can reach me on
  16.  *    CompuServe at 70441,3055.
  17.  *
  18.  *——————————————————————————————————————————————————————————————————————————————————————
  19.  *———— NOTE ——— NOTE ——— NOTE ——— NOTE ——— NOTE ——— NOTE ——— NOTE ——— NOTE ——— NOTE ————
  20.  *——————————————————————————————————————————————————————————————————————————————————————
  21.  *    If you are not familiar with programming the Apple MIDI Manager, refer to the
  22.  *    "MIDI Management Tools" Version 2.0, available from APDA.  You MUST have the
  23.  *    software (MIDI.H and the library) from this package in order to use these objects.
  24.  *    It will not work without this.
  25.  *——————————————————————————————————————————————————————————————————————————————————————
  26.  *    REVISION HISTORY:
  27.  *        August ??, 1990            - Original release (1.0).
  28.  *        November 5, 1990        - Added checks for midiMgrVer to most methods.
  29.  *        August 1991                - updated for THINK C 5.0 as version 2.0
  30.  *        July 1993                - updated for Symanctec C++ 6.0.
  31.  *——————————————————————————————————————————————————————————————————————————————————————
  32.  */
  33.  
  34. #include "CMIDIClient.h"            // This code's header file
  35.  
  36. extern    OSType    gSignature;            // Used to register client
  37.  
  38. /*
  39.  *——— gMIDIClient (global variable) ——————————————————————————————————————
  40.  * Because these objects are designed only for a single MIDI client, we
  41.  * define this global to hold it.
  42.  *————————————————————————————————————————————————————————————————————————
  43.  */
  44.  
  45. CMIDIClient * gMIDIClient = (CMIDIClient *) 0;
  46.  
  47.  
  48. /*
  49.  *——— CMIDIClient::IMIDIClient ———————————————————————————————————————————
  50.  * Initialize this object.
  51.  *
  52.  * Sign into the MIDI Manager.  Save the midiMgrVerNum.  It signs
  53.  * in with the application's name, and tries to find it's BNDL type.
  54.  * Returns an error code indicating result of initializing and signing
  55.  * into MIDI Manager.
  56.  *
  57.  * NOTE:    Only one instance of a MIDI Manager Client can be made, with
  58.  *            the current design of these objects.  Other methods assume
  59.  *            that the 'gMIDIClient' variable (defined above) points to a
  60.  *            valid CMIDIClient object.
  61.  *————————————————————————————————————————————————————————————————————————
  62.  */
  63. OSErr CMIDIClient::IMIDIClient(short theIconID)
  64. {
  65.     OSErr            err;
  66.     Handle            theIconHndl;        // Used by MIDISignIn
  67.     Str255            theName;            // me too...
  68.     short            i;                    // Junk variables
  69.     Handle            h;
  70.     unsigned long    version;
  71.  
  72.     // Make sure MIDIMgr is installed and save version number.
  73.  
  74.     midiMgrVerNum       = SndDispVersion(midiToolNum);
  75.     shortMidiMgrVerNum    = 0;
  76.  
  77.     if (midiMgrVerNum == 0)                // Damn!  Things were going so well...
  78.     {
  79.         return ErrNoMIDI;                // No MIDI driver seems to be loaded
  80.     }
  81.  
  82.     // Sign in to the MIDI Manager.
  83.  
  84.     theIconHndl = GetResource('ICN#',theIconID);    // Let’s get our icon
  85.     CheckResource(theIconHndl);            // Just checkin’...
  86.     GetAppParms(theName, &i, &h);        // Get the name of this application
  87.  
  88.     err = MIDISignIn(gSignature,         // Use application signature
  89.                         0L,                // Don’t need refCon
  90.                         theIconHndl,
  91.                         theName);        // Use theName for this MIDI client
  92.     ReleaseResource(theIconHndl);
  93.     if (err)                            // If unable to sign into MM, treat
  94.         midiMgrVerNum = 0;                // same as if no driver present.
  95.  
  96.     version = midiMgrVerNum;
  97.     version >>= 16;
  98.     shortMidiMgrVerNum = (unsigned short) version;
  99.  
  100.     return err;
  101. }
  102.  
  103. /*
  104.  *——— CMIDIClient::Dispose ————————————————————————————————————————
  105.  * Save connections, sign out of MIDI Manager.
  106.  *—————————————————————————————————————————————————————————————————
  107.  */
  108.  
  109. void CMIDIClient::Dispose(void)
  110. {
  111.      if (midiMgrVerNum)                    // If we are signed in to MM
  112.          MIDISignOut(gSignature);
  113.     inherited::Dispose();                // Call CObject method
  114. }                                        // It’s Miller Time…
  115.  
  116.  
  117. #ifndef __cplusplus
  118.  
  119.     // if using THINK C compiler, not Symantec C++, these are non-inline methods.
  120.  
  121.     MIDIIDListHdl    CMIDIClient::GetPorts(void)
  122.     {
  123.         return ((midiMgrVerNum) ? MIDIGetPorts(gSignature) : (MIDIIDListHdl) 0);
  124.     }
  125.     
  126.     Boolean            CMIDIClient::WorldChanged(void)
  127.     {
  128.         return ( (midiMgrVerNum) ? MIDIWorldChanged(gSignature) : FALSE );
  129.     }
  130.     
  131.     unsigned long    CMIDIClient::GetVerNum(void)
  132.     {
  133.         return midiMgrVerNum;
  134.     }
  135.     
  136.     unsigned short    CMIDIClient::GetShortVerNum(void)
  137.     {
  138.         return shortMidiMgrVerNum;
  139.     }
  140. #endif
  141. // end of CMIDIClient.cp
  142.